package com.rfid.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rfid.common.annotation.Log;
import com.rfid.common.enums.BusinessType;
import com.rfid.system.domain.TRfidAudit;
import com.rfid.system.service.ITRfidAuditService;
import com.rfid.common.core.controller.BaseController;
import com.rfid.common.core.domain.AjaxResult;
import com.rfid.common.utils.poi.ExcelUtil;
import com.rfid.common.core.page.TableDataInfo;

/**
 * 稽查明细Controller
 *
 * @author fangchen
 * @date 2021-01-12
 */
@Controller
@RequestMapping("/system/audit")
public class TRfidAuditController extends BaseController {
    private String prefix = "system/audit";

    @Autowired
    private ITRfidAuditService tRfidAuditService;

    @RequiresPermissions("system:audit:view")
    @GetMapping()
    public String audit() {
        return prefix + "/audit";
    }

    /**
     * 查询稽查明细列表
     */
    @RequiresPermissions("system:audit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRfidAudit tRfidAudit) {
        startPage();
        List<TRfidAudit> list = tRfidAuditService.selectTRfidAuditList(tRfidAudit);
        return getDataTable(list);
    }

    /**
     * 导出稽查明细列表
     */
    @RequiresPermissions("system:audit:export")
    @Log(title = "稽查明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRfidAudit tRfidAudit) {
        List<TRfidAudit> list = tRfidAuditService.selectTRfidAuditList(tRfidAudit);
        ExcelUtil<TRfidAudit> util = new ExcelUtil<TRfidAudit>(TRfidAudit.class);
        return util.exportExcel(list, "audit");
    }

    /**
     * 新增稽查明细
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存稽查明细
     */
    @RequiresPermissions("system:audit:add")
    @Log(title = "稽查明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRfidAudit tRfidAudit) {
        return toAjax(tRfidAuditService.insertTRfidAudit(tRfidAudit));
    }

    /**
     * 修改稽查明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TRfidAudit tRfidAudit = tRfidAuditService.selectTRfidAuditById(id);
        mmap.put("tRfidAudit", tRfidAudit);
        return prefix + "/edit";
    }

    /**
     * 修改保存稽查明细
     */
    @RequiresPermissions("system:audit:edit")
    @Log(title = "稽查明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRfidAudit tRfidAudit) {
        return toAjax(tRfidAuditService.updateTRfidAudit(tRfidAudit));
    }

    /**
     * 删除稽查明细
     */
    @RequiresPermissions("system:audit:remove")
    @Log(title = "稽查明细", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tRfidAuditService.deleteTRfidAuditByIds(ids));
    }
}
